package com.ricchieri.manage.bean;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import com.ricchieri.common.BusinessSettings;
import com.ricchieri.filter.TripFilter;
import com.ricchieri.model.Trip;
import com.ricchieri.util.FacesUtil;

@ManagedBean(name = "viewTripMB")
@ViewScoped
public class ViewTripManageBean extends GenericManageBean {

	private static final long serialVersionUID = -4431457088573798836L;
	
	private Trip trip;
	private TripFilter tripFilter;
	
	@PostConstruct
	public void init() {
		trip = (Trip) FacesUtil.getParametersFlash(BusinessSettings.KEY_TRIP);
		tripFilter = (TripFilter) FacesUtil.getParametersFlash(BusinessSettings.KEY_FILTER);
		
		if(trip == null) {
			FacesUtil.redirectToNavigationCase(BusinessSettings.SEARCH_TRIP);
		}
	}

	public Trip getTrip() {
		return trip;
	}

	public void setTrip(Trip trip) {
		this.trip = trip;
	}
	
	public String doBackToSearchTrip() {		
		FacesUtil.addParametersFlash(BusinessSettings.KEY_FILTER, tripFilter);

		return BusinessSettings.SEARCH_TRIP;
	}
}
